﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharpSphinx.Util
{


    /// <summary>
    /// An ID generator that gives out positive integer IDs and checks for overflow
    /// </summary>
    public class IDGenerator
    {

        /// <summary>
        /// Indicates a non-ID value, which is -1.
        /// </summary>
        public const int NON_ID = -1;

        private int id;




        /// <summary>
        ///  Returns the next valid ID, checks for integer overflow.
        /// </summary>
        /// <returns>the next valid ID, goes back to zero if overflow</returns>
        public int getNextID()
        {
            if (id == int.MaxValue)
            {
                return (id = 0);
            }
            else
            {
                return id++;
            }
        }

        /// <summary>
        /// Resets the ID to zero.
        /// </summary>
        public void Reset()
        {
            id = 0;
        }







    }
}
